package cn.com.oceansoft.business.szjf.service.impl;

import cn.com.oceansoft.business.szjf.entity.Sms;
import cn.com.oceansoft.business.szjf.persistence.ISmsMapper;
import cn.com.oceansoft.business.szjf.service.ISmsService;
import cn.com.oceansoft.nos.common.ISMSService;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by Administrator on 2017/6/27.
 */
@Service
public class SmsService implements ISmsService {
    //短信web地址http://wjw.szgaj.cn/smsplat/services/smsService?wsdl
//    public static final String URL_ADD_SMS = "http://wjw.szgaj.cn/smsplat/services/smsService";
    public static final String URL_ADD_SMS = "http://172.16.1.236:8084/smsplat/services/smsService";
    @Resource
    private ISmsMapper smsMapper;
    @Override
    public String getNewSmsNo() {
        String smsno = smsMapper.getSmsNo();
        if(smsno!=null && !"".equals(smsno)){
            int i = Integer.parseInt(smsno);
            smsno = String.valueOf(i+1);
        }
        return smsno;
    }

    @Override
    public void insertSMSRecords(Sms sms) {
         smsMapper.insertSMSRecords(sms);
    }

    @Override
    public void insertUserSms(Sms userSms) {
        smsMapper.insertUserSms(userSms);
    }

    /**
     * 发送短信
     * @param phone
     * @param smsContent
     * @return
     */
    @Override
    public int sendMsm(String phone, String smsContent) {
        int succ=0;
        ISMSService service1=null;
        try{
            org.codehaus.xfire.service.Service service = new ObjectServiceFactory().create(ISMSService.class);
            //发送短信6个参数
            //1、businesspk【业务主键Id】
            //2、appId【应用系统Id（由短信平台进行分配）】
            //3、moduleId【模块Id（由短信平台进行分配）】
            //4、type【短信类型（0:通知类1:回访类）】
            //5、receiveNos【接收人手机号码（多个接收人用英文半角逗号分割）】
            //6、message【短信内容】
            //sendMessage(sms.GUID, appid, "", sms.SMSTYPE, phone, sms.SMSCONTENT)
            service1 = (ISMSService)new XFireProxyFactory().create(service,URL_ADD_SMS);
            succ = service1.sendMessage("","286","","0",phone,smsContent);
        }catch (Exception e){
            succ=0;
        }
        return succ;
    }
}
